home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 48 / PC Gamer IT CD 48 2-2.iso / Starsiege / tribesdemo.exe / Disk1 / data1.cab / Tribes_Demo / base / scripts.vol / player.cs < prev    next >
Encoding:
Text File  |  1999-09-14  |  12.3 KB  |  372 lines

  1. $PlayerAnim::Crouching = 25;
  2. $PlayerAnim::DieChest = 26;
  3. $PlayerAnim::DieHead = 27;
  4. $PlayerAnim::DieGrabBack = 28;
  5. $PlayerAnim::DieRightSide = 29;
  6. $PlayerAnim::DieLeftSide = 30;
  7. $PlayerAnim::DieLegLeft = 31;
  8. $PlayerAnim::DieLegRight = 32;
  9. $PlayerAnim::DieBlownBack = 33;
  10. $PlayerAnim::DieSpin = 34;
  11. $PlayerAnim::DieForward = 35;
  12. $PlayerAnim::DieForwardKneel = 36;
  13. $PlayerAnim::DieBack = 37;
  14.  
  15. //----------------------------------------------------------------------------
  16. $CorpseTimeoutValue = 22;
  17. //----------------------------------------------------------------------------
  18.  
  19. // Player & Armor data block callbacks
  20.  
  21. function Player::onAdd(%this)
  22. {
  23.     GameBase::setRechargeRate(%this,8);
  24. }
  25.  
  26. function Player::onRemove(%this)
  27. {
  28.     // Drop anything left at the players pos
  29.     for (%i = 0; %i < 8; %i = %i + 1) {
  30.         %type = Player::getMountedItem(%this,%i);
  31.         if (%type != -1) {
  32.             // Note: Player::dropItem ius not called here.
  33.             %item = newObject("","Item",%type,1,false);
  34.          schedule("Item::Pop(" @ %item @ ");", $ItemPopTime, %item);
  35.  
  36.          addToSet("MissionCleanup", %item);
  37.             GameBase::setPosition(%item,GameBase::getPosition(%this));
  38.         }
  39.     }
  40. }
  41.  
  42. function Player::onNoAmmo(%player,%imageSlot,%itemType)
  43. {
  44.     //echo("No ammo for weapon ",%itemType.description," slot(",%imageSlot,")");
  45. }
  46.  
  47. function Player::onKilled(%this)
  48. {
  49.     %cl = GameBase::getOwnerClient(%this);
  50.     %cl.dead = 1;
  51.     if($AutoRespawn > 0)
  52.         schedule("Game::autoRespawn(" @ %cl @ ");",$AutoRespawn,%cl);
  53.     if(%this.outArea==1)    
  54.         leaveMissionAreaDamage(%cl);
  55.     Player::setDamageFlash(%this,0.75);
  56.     for (%i = 0; %i < 8; %i = %i + 1) {
  57.         %type = Player::getMountedItem(%this,%i);
  58.         if (%type != -1) {
  59.             if (%i != $WeaponSlot || !Player::isTriggered(%this,%i) || getRandom() > "0.2") 
  60.                 Player::dropItem(%this,%type);
  61.         }
  62.     }
  63.  
  64.    if(%cl != -1)
  65.    {
  66.         if(%this.vehicle != "")    {
  67.             if(%this.driver != "") {
  68.                 %this.driver = "";
  69.                  Client::setControlObject(Player::getClient(%this), %this);
  70.                  Player::setMountObject(%this, -1, 0);
  71.             }
  72.             else {
  73.                 %this.vehicle.Seat[%this.vehicleSlot-2] = "";
  74.                 %this.vehicleSlot = "";
  75.             }
  76.             %this.vehicle = "";        
  77.         }
  78.       schedule("GameBase::startFadeOut(" @ %this @ ");", $CorpseTimeoutValue, %this);
  79.       Client::setOwnedObject(%cl, -1);
  80.       Client::setControlObject(%cl, Client::getObserverCamera(%cl));
  81.       Observer::setOrbitObject(%cl, %this, 5, 5, 5);
  82.       schedule("deleteObject(" @ %this @ ");", $CorpseTimeoutValue + 2.5, %this);
  83.       %cl.observerMode = "dead";
  84.       %cl.dieTime = getSimTime();
  85.    }
  86. }
  87.  
  88. function Player::onDamage(%this,%type,%value,%pos,%vec,%mom,%vertPos,%quadrant,%object)
  89. {
  90.     if (Player::isExposed(%this)) {
  91.       %damagedClient = Player::getClient(%this);
  92.       %shooterClient = %object;
  93.  
  94.         Player::applyImpulse(%this,%mom);
  95.         if($teamplay && %damagedClient != %shooterClient && Client::getTeam(%damagedClient) == Client::getTeam(%shooterClient) ) {
  96.             if (%shooterClient != -1) {
  97.                 %curTime = getSimTime();
  98.                if ((%curTime - %this.DamageTime > 3.5 || %this.LastHarm != %shooterClient) && %damagedClient != %shooterClient && $Server::TeamDamageScale > 0) {
  99.                     if(%type != $MineDamageType) {
  100.                         Client::sendMessage(%shooterClient,0,"You just harmed Teammate " @ Client::getName(%damagedClient) @ "!");
  101.                         Client::sendMessage(%damagedClient,0,"You took Friendly Fire from " @ Client::getName(%shooterClient) @ "!");
  102.                     }
  103.                     else {
  104.                         Client::sendMessage(%shooterClient,0,"You just harmed Teammate " @ Client::getName(%damagedClient) @ " with your mine!");
  105.                         Client::sendMessage(%damagedClient,0,"You just stepped on Teamate " @ Client::getName(%shooterClient) @ "'s mine!");
  106.                     }
  107.                     %this.LastHarm = %shooterClient;
  108.                     %this.DamageStamp = %curTime;
  109.                 }
  110.             }
  111.             %friendFire = $Server::TeamDamageScale;
  112.         }
  113.         else if(%type == $ImpactDamageType && Client::getTeam(%object.clLastMount) == Client::getTeam(%damagedClient)) 
  114.             %friendFire = $Server::TeamDamageScale;
  115.         else  
  116.             %friendFire = 1.0;    
  117.  
  118.         if (!Player::isDead(%this)) {
  119.             %armor = Player::getArmor(%this);
  120.             //More damage applyed to head shots
  121.             if(%vertPos == "head" && %type == $LaserDamageType) {
  122.                 if(%armor == "harmor") { 
  123.                     if(%quadrant == "middle_back" || %quadrant == "middle_front" || %quadrant == "middle_middle") {
  124.                         %value += (%value * 0.3);
  125.                     }
  126.                 }
  127.                 else {
  128.                     %value += (%value * 0.3);
  129.                 }
  130.             }
  131.             //If Shield Pack is on
  132.             if (%type != -1 && %this.shieldStrength) {
  133.                 %energy = GameBase::getEnergy(%this);
  134.                 %strength = %this.shieldStrength;
  135.                 if (%type == $ShrapnelDamageType || %type == $MortarDamageType)
  136.                     %strength *= 0.75;
  137.                 %absorb = %energy * %strength;
  138.                 if (%value < %absorb) {
  139.                     GameBase::setEnergy(%this,%energy - ((%value / %strength)*%friendFire));
  140.                     %thisPos = getBoxCenter(%this);
  141.                     %offsetZ =((getWord(%pos,2))-(getWord(%thisPos,2)));
  142.                     GameBase::activateShield(%this,%vec,%offsetZ);
  143.                     %value = 0;
  144.                 }
  145.                 else {
  146.                     GameBase::setEnergy(%this,0);
  147.                     %value = %value - %absorb;
  148.                 }
  149.             }
  150.               if (%value) {
  151.                 %value = $DamageScale[%armor, %type] * %value * %friendFire;
  152.             %dlevel = GameBase::getDamageLevel(%this) + %value;
  153.             %spillOver = %dlevel - %armor.maxDamage;
  154.                 GameBase::setDamageLevel(%this,%dlevel);
  155.                 %flash = Player::getDamageFlash(%this) + %value * 2;
  156.                 if (%flash > 0.75) 
  157.                     %flash = 0.75;
  158.                 Player::setDamageFlash(%this,%flash);
  159.                 //If player not dead then play a random hurt sound
  160.                 if(!Player::isDead(%this)) { 
  161.                     if(%damagedClient.lastDamage < getSimTime()) {
  162.                         %sound = radnomItems(3,injure1,injure2,injure3);
  163.                         playVoice(%damagedClient,%sound);
  164.                         %damagedClient.lastdamage = getSimTime() + 1.5;
  165.                     }
  166.                 }
  167.                 else {
  168.                if(%spillOver > 0.5 && (%type== $ExplosionDamageType || %type == $ShrapnelDamageType || %type== $MortarDamageType|| %type == $MissileDamageType)) {
  169.                          Player::trigger(%this, $WeaponSlot, false);
  170.                         %weaponType = Player::getMountedItem(%this,$WeaponSlot);
  171.                         if(%weaponType != -1)
  172.                             Player::dropItem(%this,%weaponType);
  173.                     Player::blowUp(%this);
  174.                     }
  175.                     else
  176.                     {
  177.                         if ((%value > 0.40 && (%type== $ExplosionDamageType || %type == $ShrapnelDamageType || %type== $MortarDamageType || %type == $MissileDamageType )) || (Player::getLastContactCount(%this) > 6) ) {
  178.                               if(%quadrant == "front_left" || %quadrant == "front_right") 
  179.                                 %curDie = $PlayerAnim::DieBlownBack;
  180.                             else
  181.                                 %curDie = $PlayerAnim::DieForward;
  182.                         }
  183.                         else if( Player::isCrouching(%this) ) 
  184.                             %curDie = $PlayerAnim::Crouching;                            
  185.                         else if(%vertPos=="head") {
  186.                             if(%quadrant == "front_left" ||    %quadrant == "front_right"    ) 
  187.                                 %curDie = radnomItems(2, $PlayerAnim::DieHead, $PlayerAnim::DieBack);
  188.                               else 
  189.                                 %curDie = radnomItems(2, $PlayerAnim::DieHead, $PlayerAnim::DieForward);
  190.                         }
  191.                         else if (%vertPos == "torso") {
  192.                             if(%quadrant == "front_left" ) 
  193.                                 %curDie = radnomItems(3, $PlayerAnim::DieLeftSide, $PlayerAnim::DieChest, $PlayerAnim::DieForwardKneel);
  194.                             else if(%quadrant == "front_right") 
  195.                                 %curDie = radnomItems(3, $PlayerAnim::DieChest, $PlayerAnim::DieRightSide, $PlayerAnim::DieSpin);
  196.                             else if(%quadrant == "back_left" ) 
  197.                                 %curDie = radnomItems(4, $PlayerAnim::DieLeftSide, $PlayerAnim::DieGrabBack, $PlayerAnim::DieForward, $PlayerAnim::DieForwardKneel);
  198.                             else if(%quadrant == "back_right") 
  199.                                 %curDie = radnomItems(4, $PlayerAnim::DieGrabBack, $PlayerAnim::DieRightSide, $PlayerAnim::DieForward, $PlayerAnim::DieForwardKneel);
  200.                         }
  201.                         else if (%vertPos == "legs") {
  202.                             if(%quadrant == "front_left" ||    %quadrant == "back_left") 
  203.                                 %curDie = $PlayerAnim::DieLegLeft;
  204.                             if(%quadrant == "front_right" ||    %quadrant == "back_right") 
  205.                                 %curDie = $PlayerAnim::DieLegRight;
  206.                         }
  207.                         Player::setAnimation(%this, %curDie);
  208.                     }
  209.                     if(%type == $ImpactDamageType && %object.clLastMount != "")  
  210.                         %shooterClient = %object.clLastMount;
  211.                     Client::onKilled(%damagedClient,%shooterClient, %type);
  212.                 }
  213.             }
  214.         }
  215.     }
  216. }
  217.  
  218. function radnomItems(%num, %an0, %an1, %an2, %an3, %an4, %an5, %an6)
  219. {
  220.     return %an[floor(getRandom() * (%num - 0.01))];
  221. }
  222.  
  223. function Player::onCollision(%this,%object)
  224. {
  225.     if (Player::isDead(%this)) {
  226.         if (getObjectType(%object) == "Player") {
  227.             // Transfer all our items to the player
  228.             %sound = false;
  229.             %max = getNumItems();
  230.             for (%i = 0; %i < %max; %i = %i + 1) {
  231.                 %count = Player::getItemCount(%this,%i);
  232.                 if (%count) {
  233.                     %delta = Item::giveItem(%object,getItemData(%i),%count);
  234.                     if (%delta > 0) {
  235.                         Player::decItemCount(%this,%i,%delta);
  236.                         %sound = true;
  237.                     }
  238.                 }
  239.             }
  240.             if (%sound) {
  241.                 // Play pickup if we gave him anything
  242.                 playSound(SoundPickupItem,GameBase::getPosition(%this));
  243.             }
  244.         }
  245.     }
  246. }
  247.  
  248. function Player::getHeatFactor(%this)
  249. {
  250.     // Hack to avoid turret turret not tracking vehicles.
  251.     // Assumes that if we are not in the player we are
  252.     // controlling a vechicle, which is not always correct
  253.     // but should be OK for now.
  254.     %client = Player::getClient(%this);
  255.     if (Client::getControlObject(%client) != %this)
  256.         return 1.0;
  257.  
  258.    %time = getIntegerTime(true) >> 5;
  259.    %lastTime = Player::lastJetTime(%this) >> 10;
  260.  
  261.    if ((%lastTime + 1.5) < %time) {
  262.       return 0.0;
  263.    } else {
  264.       %diff = %time - %lastTime;
  265.       %heat = 1.0 - (%diff / 1.5);
  266.       return %heat;
  267.    }
  268. }
  269.  
  270. function Player::jump(%this,%mom)
  271. {
  272.    %cl = GameBase::getControlClient(%this);
  273.    if(%cl != -1)
  274.    {
  275.       %vehicle = Player::getMountObject (%this);
  276.         %this.lastMount = %vehicle;
  277.         %this.newMountTime = getSimTime() + 3.0;
  278.         Player::setMountObject(%this, %vehicle, 0);
  279.         Player::setMountObject(%this, -1, 0);
  280.         Player::applyImpulse(%pl,%mom);
  281.         playSound (GameBase::getDataName(%this).dismountSound, GameBase::getPosition(%this));
  282.    }
  283. }
  284.  
  285.  
  286. //----------------------------------------------------------------------------
  287.  
  288. function remoteKill(%client)
  289. {
  290.    if(!$matchStarted)
  291.       return;
  292.  
  293.    %player = Client::getOwnedObject(%client);
  294.    if(%player != -1 && getObjectType(%player) == "Player" && !Player::isDead(%player))
  295.    {
  296.         playNextAnim(%client);
  297.        Player::kill(%client);
  298.        Client::onKilled(%client,%client);
  299.    }
  300. }
  301.  
  302. $animNumber = 25;     
  303. function playNextAnim(%client)
  304. {
  305.     if($animNumber > 36) 
  306.         $animNumber = 25;        
  307.     Player::setAnimation(%client,$animNumber++);
  308. }
  309. function Client::takeControl(%clientId, %objectId)
  310. {
  311.    // remote control
  312.    if(%objectId == -1)
  313.    {
  314.       //echo("objectId = " @ %objectId);
  315.       return;
  316.    }
  317.  
  318.     %pl = Client::getOwnedObject(%clientId);
  319.     // If mounted to a vehicle then can't mount any other objects
  320.     if(%pl.driver != "" || %pl.vehicleSlot != "")
  321.         return;
  322.  
  323.    if(GameBase::getTeam(%objectId) != Client::getTeam(%clientId))
  324.    {
  325.       //echo(GameBase::getTeam(%objectId) @ " " @ Client::getTeam(%clientId));
  326.       return;
  327.    }
  328.    if(GameBase::getControlClient(%objectId) != -1)
  329.    {
  330.       echo("Ctrl Client = " @ GameBase::getControlClient(%objectId));
  331.       return;
  332.    }
  333.     %name = GameBase::getDataName(%objectId);
  334.     if(%name != CameraTurret && %name != DeployableTurret)
  335.    {
  336.        if(!GameBase::isPowered(%objectId)) 
  337.         {
  338.           // echo("Turret " @ %objectId @ " not powered.");
  339.           return;
  340.         }
  341.    }
  342.    if(!(Client::getOwnedObject(%clientId)).CommandTag && GameBase::getDataName(%objectId) != CameraTurret &&
  343.       !$TestCheats) {
  344.         Client::SendMessage(%clientId,0,"Must be at a Command Station to control turrets");
  345.            return;
  346.    }
  347.    if(GameBase::getDamageState(%objectId) == "Enabled") {
  348.        Client::setControlObject(%clientId, %objectId);
  349.        Client::setGuiMode(%clientId, $GuiModePlay);
  350.     }
  351. }
  352.  
  353. function remoteCmdrMountObject(%clientId, %objectIdx)
  354. {
  355.    Client::takeControl(%clientId, getObjectByTargetIndex(%objectIdx));
  356. }
  357.  
  358. function checkControlUnmount(%clientId)
  359. {
  360.    %ownedObject = Client::getOwnedObject(%clientId);
  361.    %ctrlObject = Client::getControlObject(%clientId);
  362.    if(%ownedObject != %ctrlObject)
  363.    {
  364.       if(%ownedObject == -1 || %ctrlObject == -1)
  365.          return;
  366.       if(getObjectType(%ownedObject) == "Player" && Player::getMountObject(%ownedObject) == %ctrlObject)
  367.          return;
  368.       Client::setControlObject(%clientId, %ownedObject);
  369.    }
  370. }
  371.  
  372.